/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28463
 * Date: 2022—07—10
 * Time: 14:24
 */
public class MyQueue {
    static class Node {
        public int val;
        public Node next;
        public Node(int val) {
            this.val = val;
        }
    }
    public Node head;//队列头
    public Node tail;//队列尾
    /**
     * @param val:
     * @return void
     * @description 入队
     */
    public void offer(int val) {
        Node node = new Node(val);
        if (head == null) {
            head = node;
            tail = node;
        }else {
            tail.next = node;
            tail = tail.next;
        }
    }
    /**
     * @param :
     * @return int
     * @description 出队
     */
    public int poll() {
        if(head == null) {
            return -1;
        }
        int oldVal = head.val;
        if (head.next == null) {
            head = tail = null;
        }else {
            head = head.next;
        }
        return oldVal;
    }
    /**
     * @param :
     * @return int
     * @description 查看当前队头元素
     */
    public int peek() {
        if(head == null) {
            return -1;
        }
        return head.val;
    }


}

